<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <meta charset="utf-8">
    <title>工具管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/AdminLTE.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/pagination.css">
    <script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
    <script src="${pageContext.request.contextPath}/js/pagination.js"></script>
    <script src="${pageContext.request.contextPath}/js/my.js"></script>
</head>

<body class="hold-transition skin-red sidebar-mini">
<!-- .box-body -->
<div class="box-header with-border">
    <h3 class="box-title">工具借用</h3>
</div>
<div class="box-body">
    <%--新增按钮：如果当前登录用户是管理员，页面展示新增按钮--%>
    <c:if test="${USER_SESSION.role =='ADMIN'}">
        <div class="pull-left">
            <div class="form-group form-inline">
                <div class="btn-group">
                    <button type="button" class="btn btn-default" title="新建" data-toggle="modal"
                            data-target="#addOrEditModal" onclick="resetFrom()"> 新增
                    </button>
                </div>
            </div>
        </div>
    </c:if>
    <%--新增按钮 /--%>
    <!--工具栏 数据搜索 -->
    <div class="box-tools pull-right">
        <div class="has-feedback">
            <form action="${pageContext.request.contextPath}/search" method="post">
                工具名称：<input name="name" value="${search.name}">&nbsp&nbsp&nbsp&nbsp
                <input class="btn btn-default" type="submit" value="查询">
            </form>
        </div>
    </div>
    <!--工具栏 数据搜索 /-->
    <!-- 数据列表 -->
        <div class="table-box">
            <!-- 数据表格 -->
            <table id="dataList" class="table table-bordered table-striped table-hover dataTable text-center">
                <thead>
                <tr>
                    <th class="sorting_asc">工具名称</th>
                    <th class="sorting">工具数量</th>
                    <th class="sorting">工具状态</th>
                    <th class="sorting">借用人</th>
                    <th class="sorting">借用时间</th>
                    <th class="sorting">归还时间</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${pageResult}" var="tool">
                    <tr>
                        <td> ${tool.name}</td>
                        <td>${tool.pagination}</td>
                        <td>
                            <c:if test="${tool.status ==0}">可借用</c:if>
                            <c:if test="${tool.status ==1}">借用中</c:if>
                            <c:if test="${tool.status ==2}">归还中</c:if>
                        </td>
                        <td>${tool.borrower}</td>
                        <td>${tool.borrowtime}</td>
                        <td>${tool.returntime}</td>
                        <td class="text-center">
                            <c:if test="${tool.status ==0}">
                                <button type="button" class="btn bg-olive btn-xs" data-toggle="modal" data-target="#borrowModal"
                                        onclick="findBookById(${tool.id},'borrow')"> 借用
                                </button>
                            </c:if>
                            <c:if test="${tool.status ==1 ||tool.status ==2}">
                                <button type="button" class="btn bg-olive btn-xs" disabled="true">借用</button>
                            </c:if>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>

            <button type="button" class="btn bg-olive btn-xs" onclick="prePage(${pageNum},${pages})">上一页</button>&nbsp;${pageNum}&nbsp;
            <button type="button" class="btn bg-olive btn-xs" onclick="nextPage(${pageNum},${pages})">下一页</button>
            <!-- 数据表格 /-->
        </div>
        <!-- 数据展示内容区/ -->
        <%--引入存放模态窗口的页面--%>
        <jsp:include page="/admin/tool_modal.jsp"></jsp:include>
        <script>
            function prePage(index,pages) {
                if(index>1) index=index-1;
                else index=1;
                var url="/selectPageByIndex?index="+index;
                $.get(url,function (response) {
                    console.log(response);
                });
            }
            function nextPage(index,pages) {
                if(index>=pages) index=pages;
                else index=index+1;
                var url="/selectPageByIndex?index="+index;
                $.get(url,function (response) {
                    console.log(response);
                });
            }

        </script>
</body>
</html>
